<template>
  <div>
    <el-pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :page-size="obj._limit"
      :current-page="currentPage"
      :page-sizes="Pagesizes"
      @current-change="currentChange"
      @size-change="sizeChange"
    />
  </div>
</template>

<script>
export default {
  props: {
    obj: {
      type: Object,
      required: true
    },
    total: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      currentPage: 1, // 页码
      Pagesizes: Array.from(new Set([this.obj._limit, ...[2, 5, 10, 20]]))
    }
  },
  methods: {
    // 分页点击
    currentChange(page) {
      console.log('oldPage', this.currentPage)
      console.log('page', page)
      // 通知父组件更改数据
      this.$emit('currentChange', page, this.currentPage)
      // 记录当前页码
      this.currentPage = page
    },
    // 每页显示条数变化
    sizeChange(val) {
      // 每次变化页码都重新为第一页
      this.currentPage = 1
      // 通知父组件更改数据
      this.$emit('sizeChange', val)
    }
  }
}
</script>

<style>

</style>
